package 贪心;

public class q376摆动序列 {
    public static void main(String[] args) {

        int[] nums = {0,0,0,1};
        Solution solution = new q376摆动序列().new Solution();
        System.out.println(solution.wiggleMaxLength(nums));
    }
    class Solution {
        public int wiggleMaxLength(int[] nums) {
            int res = nums.length;
            if(res==1) return res;
            if(res==2) return nums[0]==nums[1]? 1 : 2;
            int a = nums[0];
            int b = nums[1];
            int c = nums[2];
            int index = 1; // 从第二个开始
            while(index <= nums.length-2){  // 走到倒数第二个
                if(b-a >0 && c-b <0){
                    index++;
                    if(index <= nums.length-2){
                        a = nums[index -1];
                        b = nums[index];
                        c = nums[index +1];
                    }

                }else if(b-a <0 && c-b >0){

                    if(index <= nums.length-2){
                        index++;
                        a = nums[index -1];
                        b = nums[index];
                        c = nums[index +1];
                    }

                }else{  // 一直走
                    index++;
                    res --;

                    if(index <= nums.length-2){
                        b = nums[index];
                        c = nums[index+1];
                    }
                }
            }
            if(a==nums[index]) res--;
            return res;
        }
    }
}
